{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from tqdm import tqdm\n",
    "import csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "# test_data_path = '../data/testData0626.csv'\n",
    "test_data_path = '../data/testData0626_time_correction.csv'\n",
    "time_correct_test_data_path = '../data/testData0626_correction.csv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       2019-07-02 04:12:48\n",
       "1       2019-07-02 04:12:48\n",
       "2       2019-07-02 04:12:48\n",
       "3       2019-07-02 04:12:48\n",
       "4       2019-07-02 04:12:48\n",
       "                ...        \n",
       "34707   2020-03-13 06:07:28\n",
       "34708   2020-03-13 06:07:28\n",
       "34709   2020-03-13 06:07:28\n",
       "34710   2020-03-13 06:07:28\n",
       "34711   2020-03-13 06:07:28\n",
       "Name: onboardDate, Length: 34712, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_data_origin = data = pd.read_csv(test_data_path) \n",
    "test_data_origin['onboardDate'] = pd.to_datetime(test_data_origin['onboardDate'], infer_datetime_format=True)\n",
    "test_data_origin['onboardDate']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "order = 'WZ372398707823'\n",
    "h_time = -40\n",
    "test_data_origin.loc[test_data_origin['loadingOrder'] == order, 'onboardDate'] = (test_data_origin[test_data_origin['loadingOrder'] == order]['onboardDate'] + pd.Timedelta(hours=h_time)).apply(lambda x:x.strftime('%Y/%m/%d  %H:%M:%S'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>loadingOrder</th>\n",
       "      <th>timestamp</th>\n",
       "      <th>longitude</th>\n",
       "      <th>latitude</th>\n",
       "      <th>speed</th>\n",
       "      <th>direction</th>\n",
       "      <th>carrierName</th>\n",
       "      <th>vesselMMSI</th>\n",
       "      <th>onboardDate</th>\n",
       "      <th>TRANSPORT_TRACE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>AE223035353902</td>\n",
       "      <td>2019-07-03T21:16:48.000Z</td>\n",
       "      <td>120.093858</td>\n",
       "      <td>22.581320</td>\n",
       "      <td>24</td>\n",
       "      <td>29070.0</td>\n",
       "      <td>OIEQNT</td>\n",
       "      <td>C2075927370</td>\n",
       "      <td>2019-07-02 04:12:48</td>\n",
       "      <td>CNYTN-MXZLO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>AE223035353902</td>\n",
       "      <td>2019-07-03T21:34:48.000Z</td>\n",
       "      <td>120.035707</td>\n",
       "      <td>22.617522</td>\n",
       "      <td>25</td>\n",
       "      <td>34550.0</td>\n",
       "      <td>OIEQNT</td>\n",
       "      <td>C2075927370</td>\n",
       "      <td>2019-07-02 04:12:48</td>\n",
       "      <td>CNYTN-MXZLO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>AE223035353902</td>\n",
       "      <td>2019-07-03T21:51:18.000Z</td>\n",
       "      <td>119.981800</td>\n",
       "      <td>22.658465</td>\n",
       "      <td>32</td>\n",
       "      <td>30160.0</td>\n",
       "      <td>OIEQNT</td>\n",
       "      <td>C2075927370</td>\n",
       "      <td>2019-07-02 04:12:48</td>\n",
       "      <td>CNYTN-MXZLO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>AE223035353902</td>\n",
       "      <td>2019-07-03T21:54:18.000Z</td>\n",
       "      <td>119.970845</td>\n",
       "      <td>22.668688</td>\n",
       "      <td>33</td>\n",
       "      <td>33540.0</td>\n",
       "      <td>OIEQNT</td>\n",
       "      <td>C2075927370</td>\n",
       "      <td>2019-07-02 04:12:48</td>\n",
       "      <td>CNYTN-MXZLO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>AE223035353902</td>\n",
       "      <td>2019-07-03T22:11:08.000Z</td>\n",
       "      <td>119.953628</td>\n",
       "      <td>22.756897</td>\n",
       "      <td>36</td>\n",
       "      <td>35140.0</td>\n",
       "      <td>OIEQNT</td>\n",
       "      <td>C2075927370</td>\n",
       "      <td>2019-07-02 04:12:48</td>\n",
       "      <td>CNYTN-MXZLO</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34707</th>\n",
       "      <td>ZZ524449869421</td>\n",
       "      <td>2020-03-17T04:02:38.000Z</td>\n",
       "      <td>103.776707</td>\n",
       "      <td>1.252897</td>\n",
       "      <td>6</td>\n",
       "      <td>32320.0</td>\n",
       "      <td>BHSOUA</td>\n",
       "      <td>P2595193878</td>\n",
       "      <td>2020-03-13 06:07:28</td>\n",
       "      <td>CNSHK-GRPIR</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34708</th>\n",
       "      <td>ZZ524449869421</td>\n",
       "      <td>2020-03-17T04:03:18.000Z</td>\n",
       "      <td>103.776312</td>\n",
       "      <td>1.253418</td>\n",
       "      <td>6</td>\n",
       "      <td>32340.0</td>\n",
       "      <td>BHSOUA</td>\n",
       "      <td>P2595193878</td>\n",
       "      <td>2020-03-13 06:07:28</td>\n",
       "      <td>CNSHK-GRPIR</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34709</th>\n",
       "      <td>ZZ524449869421</td>\n",
       "      <td>2020-03-17T04:05:18.000Z</td>\n",
       "      <td>103.775175</td>\n",
       "      <td>1.254865</td>\n",
       "      <td>5</td>\n",
       "      <td>32030.0</td>\n",
       "      <td>BHSOUA</td>\n",
       "      <td>P2595193878</td>\n",
       "      <td>2020-03-13 06:07:28</td>\n",
       "      <td>CNSHK-GRPIR</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34710</th>\n",
       "      <td>ZZ524449869421</td>\n",
       "      <td>2020-03-17T04:05:58.000Z</td>\n",
       "      <td>103.774803</td>\n",
       "      <td>1.255285</td>\n",
       "      <td>5</td>\n",
       "      <td>31940.0</td>\n",
       "      <td>BHSOUA</td>\n",
       "      <td>P2595193878</td>\n",
       "      <td>2020-03-13 06:07:28</td>\n",
       "      <td>CNSHK-GRPIR</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34711</th>\n",
       "      <td>ZZ524449869421</td>\n",
       "      <td>2020-03-17T04:07:38.000Z</td>\n",
       "      <td>103.773883</td>\n",
       "      <td>1.256368</td>\n",
       "      <td>5</td>\n",
       "      <td>31960.0</td>\n",
       "      <td>BHSOUA</td>\n",
       "      <td>P2595193878</td>\n",
       "      <td>2020-03-13 06:07:28</td>\n",
       "      <td>CNSHK-GRPIR</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>34712 rows × 10 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         loadingOrder                 timestamp   longitude   latitude  speed  \\\n",
       "0      AE223035353902  2019-07-03T21:16:48.000Z  120.093858  22.581320     24   \n",
       "1      AE223035353902  2019-07-03T21:34:48.000Z  120.035707  22.617522     25   \n",
       "2      AE223035353902  2019-07-03T21:51:18.000Z  119.981800  22.658465     32   \n",
       "3      AE223035353902  2019-07-03T21:54:18.000Z  119.970845  22.668688     33   \n",
       "4      AE223035353902  2019-07-03T22:11:08.000Z  119.953628  22.756897     36   \n",
       "...               ...                       ...         ...        ...    ...   \n",
       "34707  ZZ524449869421  2020-03-17T04:02:38.000Z  103.776707   1.252897      6   \n",
       "34708  ZZ524449869421  2020-03-17T04:03:18.000Z  103.776312   1.253418      6   \n",
       "34709  ZZ524449869421  2020-03-17T04:05:18.000Z  103.775175   1.254865      5   \n",
       "34710  ZZ524449869421  2020-03-17T04:05:58.000Z  103.774803   1.255285      5   \n",
       "34711  ZZ524449869421  2020-03-17T04:07:38.000Z  103.773883   1.256368      5   \n",
       "\n",
       "       direction carrierName   vesselMMSI          onboardDate TRANSPORT_TRACE  \n",
       "0        29070.0      OIEQNT  C2075927370  2019-07-02 04:12:48     CNYTN-MXZLO  \n",
       "1        34550.0      OIEQNT  C2075927370  2019-07-02 04:12:48     CNYTN-MXZLO  \n",
       "2        30160.0      OIEQNT  C2075927370  2019-07-02 04:12:48     CNYTN-MXZLO  \n",
       "3        33540.0      OIEQNT  C2075927370  2019-07-02 04:12:48     CNYTN-MXZLO  \n",
       "4        35140.0      OIEQNT  C2075927370  2019-07-02 04:12:48     CNYTN-MXZLO  \n",
       "...          ...         ...          ...                  ...             ...  \n",
       "34707    32320.0      BHSOUA  P2595193878  2020-03-13 06:07:28     CNSHK-GRPIR  \n",
       "34708    32340.0      BHSOUA  P2595193878  2020-03-13 06:07:28     CNSHK-GRPIR  \n",
       "34709    32030.0      BHSOUA  P2595193878  2020-03-13 06:07:28     CNSHK-GRPIR  \n",
       "34710    31940.0      BHSOUA  P2595193878  2020-03-13 06:07:28     CNSHK-GRPIR  \n",
       "34711    31960.0      BHSOUA  P2595193878  2020-03-13 06:07:28     CNSHK-GRPIR  \n",
       "\n",
       "[34712 rows x 10 columns]"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "test_data_origin"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_data_origin.to_csv(time_correct_test_data_path,index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.7.6 64-bit ('AI': conda)",
   "language": "python",
   "name": "python37664bitaiconda6859e03b37c34f0182c9bde8073269f7"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
